package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teaching.domain.TeachingTeacher;
import com.ruoyi.teaching.service.ITeachingTeacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 老师信息Controller
 * 
 * @author ruoyi
 * @date 2022-03-21
 */
@RestController
@RequestMapping("/teaching/teacher")
public class TeachingTeacherController extends BaseController
{
    @Autowired
    private ITeachingTeacherService teachingTeacherService;

    /**
     * 查询老师信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingTeacher teachingTeacher)
    {
        startPage();
        List<TeachingTeacher> list = teachingTeacherService.selectTeachingTeacherList(teachingTeacher);
        return getDataTable(list);
    }

    @GetMapping(value = "/listAll")
    public AjaxResult getAll()
    {
        TeachingTeacher teachingTeacher = new TeachingTeacher();
        List<TeachingTeacher> list = teachingTeacherService.selectTeachingTeacherList(teachingTeacher);
        return AjaxResult.success(list);
    }

    /**
     * 导出老师信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:teacher:export')")
    @Log(title = "老师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingTeacher teachingTeacher)
    {
        List<TeachingTeacher> list = teachingTeacherService.selectTeachingTeacherList(teachingTeacher);
        ExcelUtil<TeachingTeacher> util = new ExcelUtil<TeachingTeacher>(TeachingTeacher.class);
        util.exportExcel(response, list, "老师信息数据");
    }

    /**
     * 获取老师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:teacher:query')")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") Long teacherId)
    {
        return AjaxResult.success(teachingTeacherService.selectTeachingTeacherByTeacherId(teacherId));
    }

    /**
     * 新增老师信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:teacher:add')")
    @Log(title = "老师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingTeacher teachingTeacher)
    {
        return toAjax(teachingTeacherService.insertTeachingTeacher(teachingTeacher));
    }

    /**
     * 修改老师信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:teacher:edit')")
    @Log(title = "老师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingTeacher teachingTeacher)
    {
        return toAjax(teachingTeacherService.updateTeachingTeacher(teachingTeacher));
    }

    /**
     * 删除老师信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:teacher:remove')")
    @Log(title = "老师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Long[] teacherIds)
    {
        return toAjax(teachingTeacherService.deleteTeachingTeacherByTeacherIds(teacherIds));
    }
}
